﻿using System;
using System.ComponentModel;
using System.Globalization;

namespace Gmantis.Controls
{
    internal class StringToObjectConverter : StringTypeConverter
    {
        // Fields
        private bool _convertFromStringToString;

        // Methods
        public StringToObjectConverter(bool convertFromStringToString)
        {
            this._convertFromStringToString = convertFromStringToString;
        }

        public override object ConvertFromString(ITypeDescriptorContext context, CultureInfo culture, string text)
        {
            if (this._convertFromStringToString)
            {
                return text;
            }
            return null;
        }

        public override string ConvertToString(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            if (value != null)
            {
                return value.ToString();
            }
            return string.Empty;
        }
    }
}
